package com.roc.web.action.terminal;
import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;

@SuppressWarnings("serial")
public class TerminalDownLoadSearchCondition extends BaseSearchCondition{
	private String mchtCd;
	private String start;
	private String end;
	private String flag;
	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();
		if (Constance.isNotEmpty(mchtCd)){
			filedBeanList.add(new WhereHQLFieldBean("mcht_cd",mchtCd.trim(),"=", false));
		}
		if (Constance.isNotEmpty(start)){
			filedBeanList.add(new WhereHQLFieldBean("dates",start.trim(),">=", false));		
		}
		if (Constance.isNotEmpty(end)){
			filedBeanList.add(new WhereHQLFieldBean("dates",end.trim(),"<=", false));		
		}
		return filedBeanList;
	}

	@Override
	protected String getRowCountHQL() {
		StringBuffer sb=new StringBuffer();
		sb.append(" select count(*) from ("
				+ " select a.mcht_cd,a.term_id,a.term_id_id sn,substr(m.dic_name, 4) brand,"
				+ " case b.term_tp when '1' then '固定POS' when '3' then '移动POS' end tp,"
				+ " n.name models,a.remark1 dates,b.installlocation address from apstfr.tbl_MCHT_sn_inf a,"
				+ " tbl_term_inf b,tbl_dictionaryitem m,tbl_dictionarylayeritem n "
				+ " where a.remark3 = '02' and a.remark2 = '0' and m.dic_type = 'TMNL_BRAND' "
				+ " and n.dic_type = 'TMNL_MODEL_NO' and m.dic_code = b.tmnl_brand "
				+ " and n.dic_pcode = b.tmnl_brand and n.dic_code = b.tmnl_model_no "
				+ " and b.mcht_cd=a.mcht_cd and b.term_id=a.term_id "
				+ " union all "
				+ " select a.mcht_cd,a.term_id,a.term_id_id sn,b.remark1 brand,"
				+ " case a.term_tp when '02' then '传统POS' when '03' then 'MPOS' when '04' then '智能POS' end tp,"
				+ " b.remark2 models,a.remark1 dates,c.reg_addr address from apstfr.tbl_MCHT_sn_inf a,apstfr.tbl_TERM_sn_inf b, "
				+ " tbl_mcht_inf c where a.term_id_id = b.term_id_id and a.mcht_cd=c.mcht_cd and a.remark3 = '04' and a.remark2 = '0' and b.flag = '1') "
				+ " where 1=1 ");		
		return sb.toString();
	}

	@Override
	protected String getSearchHQL() {
		StringBuffer sb=new StringBuffer();
		sb.append(" select mcht_cd,term_id,sn,brand,tp,models,dates,address from ("
				+ " select a.mcht_cd,a.term_id,a.term_id_id sn,substr(m.dic_name, 4) brand,"
				+ " case b.term_tp when '1' then '固定POS' when '3' then '移动POS' end tp,"
				+ " n.name models,a.remark1 dates,b.installlocation address from apstfr.tbl_MCHT_sn_inf a,"
				+ " tbl_term_inf b,tbl_dictionaryitem m,tbl_dictionarylayeritem n "
				+ " where a.remark3 = '02' and a.remark2 = '0' and m.dic_type = 'TMNL_BRAND' "
				+ " and n.dic_type = 'TMNL_MODEL_NO' and m.dic_code = b.tmnl_brand "
				+ " and n.dic_pcode = b.tmnl_brand and n.dic_code = b.tmnl_model_no "
				+ " and b.mcht_cd=a.mcht_cd and b.term_id=a.term_id "
				+ " union all "
				+ " select a.mcht_cd,a.term_id,a.term_id_id sn,b.remark1 brand,"
				+ " case a.term_tp when '02' then '传统POS' when '03' then 'MPOS' when '04' then '智能POS' end tp,"
				+ " b.remark2 models,a.remark1 dates,c.reg_addr address from apstfr.tbl_MCHT_sn_inf a,apstfr.tbl_TERM_sn_inf b, "
				+ " tbl_mcht_inf c where a.term_id_id = b.term_id_id and a.mcht_cd=c.mcht_cd and a.remark3 = '04' and a.remark2 = '0' and b.flag = '1') "
				+ " where 1=1 ");		
		return sb.toString();
	}

	@Override
	protected String getOrderPartOfHQL() {
		return " order by mcht_cd,term_id ";
	}

	public String getMchtCd() {
		return mchtCd;
	}

	public void setMchtCd(String mchtCd) {
		this.mchtCd = mchtCd;
	}

	public String getStart() {
		return start;
	}

	public void setStart(String start) {
		this.start = start;
	}

	public String getEnd() {
		return end;
	}

	public void setEnd(String end) {
		this.end = end;
	}

	public String getFlag() {
		return flag;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}
	
}
